<template>
    <div class="default-main ba-table-box">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info" show-icon />

        <!-- 表格顶部菜单 -->
        <TableHeader :buttons="['refresh', 'comSearch']" />

        <!-- 表格 -->
        <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
        <Table ref="tableRef" />
    </div>
</template>

<script setup lang="ts">
import { ref, provide, onMounted } from 'vue'
import baTableClass from '/@/utils/baTable'
import { baTableApi } from '/@/api/common'
import { useI18n } from 'vue-i18n'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'

const { t } = useI18n()
const tableRef = ref()

const baTable = new baTableClass(
    new baTableApi('/admin/xmwms.InventoryHistory/'),
    {
        pk: 'id',
        column: [
            {
                label: t('xmwms.inventoryHistory.order_no'),
                prop: 'order_no',
                align: 'center',
                width: '150',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.product_no'),
                prop: 'product.product_no',
                align: 'center',
                width: '200',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.product_name'),
                prop: 'product.name',
                align: 'center',
                width: '200',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.quantity'),
                prop: 'quantity',
                align: 'center',
                width: '100',
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.price'),
                prop: 'price',
                align: 'center',
                width: '100',
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.total_price'),
                prop: 'total_price',
                align: 'center',
                width: '100',
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.unit_name'),
                prop: 'product.wmsUnit.name',
                align: 'center',
                width: '100',
                operatorPlaceholder: t('Fuzzy query'),
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.spec'),
                prop: 'product.spec',
                align: 'center',
                width: '100',
                operatorPlaceholder: t('Fuzzy query'),
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.warehouse_shelf'),
                prop: 'warehouse_shelf_id_text',
                align: 'center',
                width: '200',
                operatorPlaceholder: t('Fuzzy query'),
                render: 'tags',
                operator: false,
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.form_type'),
                prop: 'form_type',
                align: 'center',
                width: '100',
                render: 'tag',
                operator: '=',
                sortable: false,
                replaceValue: {
                    10: t('xmwms.inventoryHistory.form_type 10'),
                    20: t('xmwms.inventoryHistory.form_type 20'),
                    30: t('xmwms.inventoryHistory.form_type 30'),
                    40: t('xmwms.inventoryHistory.form_type 40'),
                    50: t('xmwms.inventoryHistory.form_type 50'),
                    60: t('xmwms.inventoryHistory.form_type 60'),
                    70: t('xmwms.inventoryHistory.form_type 70'),
                },
            },
            {
                label: t('xmwms.inventoryHistory.admin__username'),
                prop: 'admin.username',
                align: 'center',
                width: '100',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'LIKE',
                sortable: false,
            },
            {
                label: t('xmwms.inventoryHistory.updatetime'),
                prop: 'update_time',
                align: 'center',
                width: '160',
                render: 'datetime',
                operatorPlaceholder: t('Fuzzy query'),
                operator: 'RANGE',
                sortable: false,
                timeFormat: 'yyyy-mm-dd hh:MM:ss',
            },
        ],
        dblClickNotEditColumn: [undefined],
    },
    {
        defaultItems: {},
    }
)

provide('baTable', baTable)

onMounted(() => {
    baTable.table.ref = tableRef.value
    baTable.mount()
    baTable.getIndex()?.then(() => {
        baTable.initSort()
        baTable.dragSort()
    })
})
</script>

<script lang="ts">
import { defineComponent } from 'vue'
export default defineComponent({
    name: 'xmwms/InventoryHistory',
})
</script>

<style scoped lang="scss"></style>
